define(['text!T_FooterView','m_zepto','m_swipe','m_tab','m_tpl'],function(T_FooterView) {
    $(function(){
        var hashValue = sessionStorage.getItem("indexHash");  
        if(!hashValue){
            hashValue = getHashParams().__vpageid; 
        }
        pageInit(hashValue);
        var ua = navigator.userAgent.toLowerCase();//获取判断用的对象
        // if (ua.match(/MicroMessenger/i) != "micromessenger") {
            if(iswechat()==false&&!localStorage.getItem("safeExit")){
                $('footer').html((_.template(T_FooterView)()));
            }
        var curIndex = $.inArray(hashValue,['p_view_home','p_view_funds','p_view_wealth','p_view_more']);
 
        tab = $('#nf-tab').tab({
            curIndex:(curIndex<0)?0:curIndex,
            data:['首页','产品','资产','我的'],
            callback:pageInit,
            clickFunc:getCouponData
        });
        if(islogin()){
          // if (localStorage.getItem('originalString') == 'DCVALID') {
              // dialogConfirm('您还未开通直销账户，请先开户','开户','openAccount.html');
           // }
           //judgeRisk();//更新riskexpired 新开户未做风险测评也当做风险过期
            $('#btn-login').text('安全退出').on('click',function(){
                clearLocVal("sessionkey,idtype");
                sessionStorage.removeItem("loginflag")
                judgeJumpReloginUrl('index.html');
            })
        }else{
            $('#btn-login').on('click',function(){
                judgeJumpReloginUrl('login.html');
            })
        }
        if( ('onhashchange'in window) && ((typeof document.documentMode==='undefined') || document.documentMode==8)) { // 浏览器支持onhashchange事件
            window.onhashchange = function(){ // TODO，对应新的hash执行的操作函数
                //var hashValue = getHashParams().__vpageid;
                //var curIndex = $.inArray(hashValue,['p_view_home','p_view_funds','p_view_wealth','p_view_more']);
                //tab.itemClick(curIndex);
            };
        } else { // 不支持则用定时器检测的办法
            //setInterval(function() {
            //    var ischanged = isHashChanged(); // 检测hash值或其中某一段是否更改的函数， 在低版本的iE浏览器中通过window.location.hash取出的指和其它的浏览器不同，要注意
            //    if(ischanged) {
            //       // hashChangeFire();  // TODO，对应新的hash执行的操作函数
            //    }
            //}, 150);
        }
        if(!localStorage.getItem('isDownload')){
            $('.banner-download-del').on('click',function(){
                localStorage.setItem('isDownload','close');
                $('#banner-download').remove();
            });
        }
    });
    function pageInit(nextPage){
        //对头部进行变化
        if(nextPage==''){
             $('.virtualTitle').css({display:'none !important'});
            $('.virtualTitle[page="p_view_home"]').css({display:''});
        }else{
            $('.virtualTitle').css({display:'none !important'});
            $('.virtualTitle[page="'+nextPage+'"]').css({display:''});
        }
        
        
        if(iswechat()&&islogin()==false&&!isnotBind()){
             wechatlogin(pageInitCallback,1,nextPage);
        }else{
            pageInitCallback(nextPage);
        }        
    }
    function pageInitCallback(nextPage){      
        
        var hashValue = sessionStorage.getItem("indexHash");  
        if(!hashValue){
            hashValue = getHashParams().__vpageid; 
        }
        var curIndex = $.inArray(hashValue,['p_view_home','p_view_funds','p_view_wealth','p_view_more']);
 
       // if(!islogin()&&curIndex==2){
            // curIndex = 0;//修正未登录初始化
        // }
         if(nextPage=='p_view_funds'){
            piwikTrackEvent(Piwik_Event_Quota.index.category,Piwik_Event_Quota.index.product.action,"");
            var p_funds = require(['p_funds']);
        }else if(nextPage=='p_view_wealth'){
            // if(!islogin()){//未登录自动条状登陆页面
                // judgeJumpReloginUrl("login.html?#p_view_wealth");
            // }else{
                if(iswechat()&&!checkLock()){//微信登录增加手势密码验证
                      return;
                }
                piwikTrackEvent(Piwik_Event_Quota.index.category,Piwik_Event_Quota.index.wealth.action,"");   
                var p_wealth = require(['p_wealth']);
            // }
        }else if(nextPage=='p_view_more'){
            piwikTrackEvent(Piwik_Event_Quota.index.category,Piwik_Event_Quota.index.more.action,"");
            var p_more = require(['p_more']);
        }else{
            piwikTrackEvent(Piwik_Event_Quota.index.category,Piwik_Event_Quota.index.index.action,"");
            var p_funds = require(['p_home']);
        }
        
    }
});
//事件绑定

$('#searchBtn').on('click',function(){
       window.location.href  = 'fundSearch.html';
});
//交易记录
$('#trede-record').on('click',function(){
       window.location.href  = 'tradeRecord.html';
});
//消息
// $('#mesBtn').on('click',function(){
       // window.location.href  = 'publishMsgCenter.html';
// });


